# -*- coding: utf-8 -*-
import scrapy


class MovieSpider(scrapy.Spider):
    name = 'movie'
    allowed_domains = ['www.dytt8.net']
    # start_urls = ['http://www.dytt8.net/']

    def start_requests(self):
        urls = ['http://www.dytt8.net']
        for url in urls:
            # 请求url
            yield scrapy.Request(url, callback=self.parse)

    def parse(self, response):
        """
        解析服务器返回的response
        :param response:
        :return:
        """
        # with open('dianying.html','wb') as f:
        #     f.write(response.body)

        movies = response.css('div.co_content2 > ul > a')
        for movie in movies:
            item = {}
            # print(movie.css('::text').extract()[0])
            item['name'] = movie.css('::text').extract_first()
            item['url'] = movie.css('::attr(href)').extract_first()
            yield item